//package expressaoevolutiva;

import java.util.*;

public class Ackley
{
	int c1 = 20;
	float c2 = (float)0.2;
	double c3 = 2 * Math.PI;
	double[] x;
	int n;


	double value;

	public Ackley(double[] x)
	{
		this.n = x.length;
		this.x = x;

		value = -c1 * Math.exp(-c2*Math.sqrt((1./n)*Somatorio1())) -Math.exp((1./n)*Somatorio2()) + c1 + Math.E;
	}

	public double getValue()
	{
		return value;
	}

    public double Somatorio1()
    {
        double soma = 0;

        for (int i=0; i < x.length; i++)
        {
            soma += Math.pow(x[i],2);
        }

        return soma;
    }

    public double Somatorio2()
    {
    	double soma = 0;

    	for (int i=0; i<x.length; i++)
    	{
    		soma += Math.cos(c3*x[i]);
    	}

    	return soma;
    }

}
